package com.example.mapreducr.writable;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * ClassName: WordDriver
 * Package: com.example.mapreducr.wordcount
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-07-15
 * Time: 20:54
 */

public class WordDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        //1.获取配置信息 获取job对象实列
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        //2.制定程序jar包所在本地路径
        job.setJarByClass(WordDriver.class);

        //3.关联Mapper/Reducer业务类
        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReduce.class);

        //4.指定Mapper输出数据的kv类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);

        //5.指定最终输出输出的kv类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);

        //6.指定job出入原始文件路径 可以指定文件 或者 目录
        //7.指定job输出结果所在目录
        FileInputFormat.setInputPaths(job, new Path("E:/input/inputflow"));
        FileOutputFormat.setOutputPath(job, new Path("E:/input/out111"));

        //8.提交作业
        boolean b = job.waitForCompletion(true);
        System.out.println(b ? 0 : 1);

    }
}
